//
// winter - Direct2D GUI framework.
// Copyright (C) 2009 Aleksandar Dezelin 
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef EVENT_SINK_H
#define EVENT_SINK_H

#pragma once
#include <deque>

namespace winter {
namespace events {

///
/// <summary>
///     Implements event sink templatized by delegate type.
/// </summary>
///
template<typename delegate_type>
class event_sink {
public:
  typedef typename std::deque<delegate_type> delegate_deque_type;
  typedef typename delegate_deque_type::const_iterator const_iterator;

  ///
  /// <summary>
  ///     Operator for adding delegates to the invocation list.
  /// </summary>
  /// <param name="d">
  ///     Delegate to be invoked somewhere.
  /// </param>
  ///
  void operator += (delegate_type d) {
    _delegates.push_back(d);
  }

  ///
  /// <summary>
  ///     Returns iterator that points to the beginning of the
  ///     delegates list.
  /// </summary>
  /// <returns>
  ///     Iterator.
  /// </returns>
  ///
  const_iterator begin() const {
    return _delegates.begin();
  }

  ///
  /// <summary>
  ///     Returns iterator that points to the end of the
  ///     delegates list.
  /// </summary>
  /// <returns>
  ///     Iterator.
  /// </returns>
  ///
  const_iterator end() const {
    return _delegates.end();
  }

private:
  delegate_deque_type _delegates;
};

}
}

#endif // EVENT_SINK_H
